<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"/><meta name="viewport" content="width=device-width, initial-scale=0.8"/><title>2.3&nbsp;列表、迭代和递归</title><link rel="stylesheet" type="text/css" href="scribble.css" title="default"/><link rel="stylesheet" type="text/css" href="racket.css" title="default"/><link rel="stylesheet" type="text/css" href="manual-style.css" title="default"/><link rel="stylesheet" type="text/css" href="manual-racket.css" title="default"/><script type="text/javascript" src="scribble-common.js"></script><script type="text/javascript" src="manual-racket.js"></script><!--[if IE 6]><style type="text/css">.SIEHidden { overflow: hidden; }</style><![endif]--></head><body id="scribble-racket-lang-org"><div class="tocset"><div class="tocview"><div class="tocviewlist tocviewlisttopspace"><div class="tocviewtitle"><table cellspacing="0" cellpadding="0"><tr><td style="width: 1em;"><a href="javascript:void(0);" title="Expand/Collapse" class="tocviewtoggle" onclick="TocviewToggle(this,&quot;tocview_0&quot;);">&#9658;</a></td><td></td><td><a href="index.html" class="tocviewlink" data-pltdoc="x">Racket&#25351;&#21335;</a></td></tr></table></div><div class="tocviewsublisttop" style="display: none;" id="tocview_0"><table cellspacing="0" cellpadding="0"><tr><td align="right">1&nbsp;</td><td><a href="intro.html" class="tocviewlink" data-pltdoc="x">&#27426;&#36814;&#26469;&#21040;Racket!</a></td></tr><tr><td align="right">2&nbsp;</td><td><a href="to-scheme.html" class="tocviewselflink" data-pltdoc="x">Racket&#27010;&#35201;</a></td></tr><tr><td align="right">3&nbsp;</td><td><a href="datatypes.html" class="tocviewlink" data-pltdoc="x">&#20869;&#32622;&#30340;&#25968;&#25454;&#31867;&#22411;</a></td></tr><tr><td align="right">4&nbsp;</td><td><a href="scheme-forms.html" class="tocviewlink" data-pltdoc="x">&#34920;&#36798;&#24335;&#21644;&#23450;&#20041;</a></td></tr><tr><td align="right">5&nbsp;</td><td><a href="define-struct.html" class="tocviewlink" data-pltdoc="x">&#31243;&#24207;&#21592;&#23450;&#20041;&#30340;&#25968;&#25454;&#31867;&#22411;</a></td></tr><tr><td align="right">6&nbsp;</td><td><a href="modules.html" class="tocviewlink" data-pltdoc="x">&#27169;&#22359;</a></td></tr><tr><td align="right">7&nbsp;</td><td><a href="contracts.html" class="tocviewlink" data-pltdoc="x">&#21512;&#32422;</a></td></tr><tr><td align="right">8&nbsp;</td><td><a href="i_o.html" class="tocviewlink" data-pltdoc="x">&#36755;&#20837;&#21644;&#36755;&#20986;</a></td></tr><tr><td align="right">9&nbsp;</td><td><a href="regexp.html" class="tocviewlink" data-pltdoc="x">&#27491;&#21017;&#34920;&#36798;&#24335;</a></td></tr><tr><td align="right">10&nbsp;</td><td><a href="control.html" class="tocviewlink" data-pltdoc="x">&#24322;&#24120;&#19982;&#25511;&#21046;</a></td></tr><tr><td align="right">11&nbsp;</td><td><a href="for.html" class="tocviewlink" data-pltdoc="x">&#36845;&#20195;&#21644;&#25512;&#23548;</a></td></tr><tr><td align="right">12&nbsp;</td><td><a href="match.html" class="tocviewlink" data-pltdoc="x">&#27169;&#24335;&#21305;&#37197;</a></td></tr><tr><td align="right">13&nbsp;</td><td><a href="classes.html" class="tocviewlink" data-pltdoc="x">&#31867;&#21644;&#23545;&#35937;</a></td></tr><tr><td align="right">14&nbsp;</td><td><a href="units.html" class="tocviewlink" data-pltdoc="x">&#21333;&#20803;</a></td></tr><tr><td align="right">15&nbsp;</td><td><a href="reflection.html" class="tocviewlink" data-pltdoc="x">&#21453;&#23556;&#21644;&#21160;&#24577;&#27714;&#20540;</a></td></tr><tr><td align="right">16&nbsp;</td><td><a href="macros.html" class="tocviewlink" data-pltdoc="x">&#23439;</a></td></tr><tr><td align="right">17&nbsp;</td><td><a href="languages.html" class="tocviewlink" data-pltdoc="x">&#21019;&#36896;&#35821;&#35328;</a></td></tr><tr><td align="right">18&nbsp;</td><td><a href="concurrency.html" class="tocviewlink" data-pltdoc="x">&#24182;&#21457;&#19982;&#21516;&#27493;</a></td></tr><tr><td align="right">19&nbsp;</td><td><a href="performance.html" class="tocviewlink" data-pltdoc="x">&#24615;&#33021;</a></td></tr><tr><td align="right">20&nbsp;</td><td><a href="parallelism.html" class="tocviewlink" data-pltdoc="x">&#24182;&#34892;</a></td></tr><tr><td align="right">21&nbsp;</td><td><a href="running.html" class="tocviewlink" data-pltdoc="x">&#36816;&#34892;&#21644;&#21019;&#24314;&#21487;&#25191;&#34892;&#31243;&#24207;</a></td></tr><tr><td align="right">22&nbsp;</td><td><a href="More_Libraries.html" class="tocviewlink" data-pltdoc="x">&#26356;&#22810;&#30340;&#24211;</a></td></tr><tr><td align="right">23&nbsp;</td><td><a href="dialects.html" class="tocviewlink" data-pltdoc="x">Racket&#21644;Scheme&#30340;&#26041;&#35328;</a></td></tr><tr><td align="right">24&nbsp;</td><td><a href="other-editors.html" class="tocviewlink" data-pltdoc="x">&#21629;&#20196;&#34892;&#24037;&#20855;&#21644;&#20320;&#30340;&#32534;&#36753;&#22120;&#36873;&#25321;</a></td></tr><tr><td align="right"></td><td><a href="doc-bibliography.html" class="tocviewlink" data-pltdoc="x">Bibliography</a></td></tr><tr><td align="right"></td><td><a href="doc-index.html" class="tocviewlink" data-pltdoc="x">Index</a></td></tr></table></div></div><div class="tocviewlist"><table cellspacing="0" cellpadding="0"><tr><td style="width: 1em;"><a href="javascript:void(0);" title="Expand/Collapse" class="tocviewtoggle" onclick="TocviewToggle(this,&quot;tocview_1&quot;);">&#9660;</a></td><td>2&nbsp;</td><td><a href="to-scheme.html" class="tocviewlink" data-pltdoc="x">Racket&#27010;&#35201;</a></td></tr></table><div class="tocviewsublist" style="display: block;" id="tocview_1"><table cellspacing="0" cellpadding="0"><tr><td align="right">2.1&nbsp;</td><td><a href="Simple_Values.html" class="tocviewlink" data-pltdoc="x">&#31616;&#21333;&#30340;&#20540;</a></td></tr><tr><td align="right">2.2&nbsp;</td><td><a href="syntax-overview.html" class="tocviewlink" data-pltdoc="x">&#31616;&#21333;&#30340;&#23450;&#20041;&#21644;&#34920;&#36798;&#24335;</a></td></tr><tr><td align="right">2.3&nbsp;</td><td><a href="" class="tocviewselflink" data-pltdoc="x">&#21015;&#34920;&#12289;&#36845;&#20195;&#21644;&#36882;&#24402;</a></td></tr><tr><td align="right">2.4&nbsp;</td><td><a href="Pairs-Lists-and-Racket-Syntax.html" class="tocviewlink" data-pltdoc="x">pair&#12289;list&#21644;Racket&#30340;&#35821;&#27861;</a></td></tr></table></div></div><div class="tocviewlist"><table cellspacing="0" cellpadding="0"><tr><td style="width: 1em;"><a href="javascript:void(0);" title="Expand/Collapse" class="tocviewtoggle" onclick="TocviewToggle(this,&quot;tocview_2&quot;);">&#9658;</a></td><td>2.3&nbsp;</td><td><a href="" class="tocviewselflink" data-pltdoc="x">&#21015;&#34920;&#12289;&#36845;&#20195;&#21644;&#36882;&#24402;</a></td></tr></table><div class="tocviewsublistbottom" style="display: none;" id="tocview_2"><table cellspacing="0" cellpadding="0"><tr><td align="right">2.3.1&nbsp;</td><td><a href="#%28part._.Predefined-.List-.Loops%29" class="tocviewlink" data-pltdoc="x">&#39044;&#23450;&#20041;&#21015;&#34920;&#24490;&#29615;</a></td></tr><tr><td align="right">2.3.2&nbsp;</td><td><a href="#%28part._.List-.Iteration-from-.Scratch%29" class="tocviewlink" data-pltdoc="x">&#20174;&#22836;&#24320;&#22987;&#21015;&#34920;&#36845;&#20195;</a></td></tr><tr><td align="right">2.3.3&nbsp;</td><td><a href="#%28part._tail-recursion%29" class="tocviewlink" data-pltdoc="x">&#23614;&#36882;&#24402;</a></td></tr><tr><td align="right">2.3.4&nbsp;</td><td><a href="#%28part._.Recursion-versus-.Iteration%29" class="tocviewlink" data-pltdoc="x">&#36882;&#24402;&#21644;&#36845;&#20195;</a></td></tr></table></div></div></div><div class="tocsub"><div class="tocsubtitle">On this page:</div><table class="tocsublist" cellspacing="0"><tr><td><span class="tocsublinknumber">2.3.1<tt>&nbsp;</tt></span><a href="#%28part._.Predefined-.List-.Loops%29" class="tocsubseclink" data-pltdoc="x">&#39044;&#23450;&#20041;&#21015;&#34920;&#24490;&#29615;</a></td></tr><tr><td><span class="tocsublinknumber">2.3.2<tt>&nbsp;</tt></span><a href="#%28part._.List-.Iteration-from-.Scratch%29" class="tocsubseclink" data-pltdoc="x">&#20174;&#22836;&#24320;&#22987;&#21015;&#34920;&#36845;&#20195;</a></td></tr><tr><td><span class="tocsublinknumber">2.3.3<tt>&nbsp;</tt></span><a href="#%28part._tail-recursion%29" class="tocsubseclink" data-pltdoc="x">&#23614;&#36882;&#24402;</a></td></tr><tr><td><span class="tocsublinknumber">2.3.4<tt>&nbsp;</tt></span><a href="#%28part._.Recursion-versus-.Iteration%29" class="tocsubseclink" data-pltdoc="x">&#36882;&#24402;&#21644;&#36845;&#20195;</a></td></tr></table></div></div><div class="maincolumn"><div class="main"><div class="navsettop"><span class="navleft"><div class="nosearchform"></div>&nbsp;&nbsp;</span><span class="navright">&nbsp;&nbsp;<a href="syntax-overview.html" title="backward to &quot;2.2 简单的定义和表达式&quot;" data-pltdoc="x">&larr; prev</a>&nbsp;&nbsp;<a href="to-scheme.html" title="up to &quot;2 Racket概要&quot;" data-pltdoc="x">up</a>&nbsp;&nbsp;<a href="Pairs-Lists-and-Racket-Syntax.html" title="forward to &quot;2.4 pair、list和Racket的语法&quot;" data-pltdoc="x">next &rarr;</a></span>&nbsp;</div><h4>2.3<tt>&nbsp;</tt><a name="(part._.Lists-.Iteration-and-.Recursion)"></a>&#21015;&#34920;&#12289;&#36845;&#20195;&#21644;&#36882;&#24402;</h4><p>Racket&#35821;&#35328;&#26159;Lisp&#35821;&#35328;&#30340;&#19968;&#31181;&#26041;&#35328;&#65292;&#21517;&#23383;&#26469;&#33258;&#20110;&#8220;LISt Processor&#8221;&#12290;&#20869;&#32622;&#30340;&#21015;&#34920;&#25968;&#25454;&#31867;&#22411;&#20445;&#30041;&#20102;&#36825;&#31181;&#35821;&#35328;&#30340;&#19968;&#20010;&#26174;&#33879;&#29305;&#24449;&#12290;</p><p><span class="RktSym"><span class="badlink"><span class="RktValLink">list</span></span></span>&#20989;&#25968;&#25509;&#21463;&#20219;&#24847;&#25968;&#37327;&#30340;&#20540;&#24182;&#36820;&#22238;&#19968;&#20010;&#21253;&#21547;&#36825;&#20123;&#20540;&#30340;&#21015;&#34920;&#65306;</p><blockquote class="SCodeFlow"><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><span class="stt">&gt; </span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">list</span></span></span><span class="hspace">&nbsp;</span><span class="RktVal">"red"</span><span class="hspace">&nbsp;</span><span class="RktVal">"green"</span><span class="hspace">&nbsp;</span><span class="RktVal">"blue"</span><span class="RktPn">)</span></td></tr><tr><td><p><span class="RktRes">'("red" "green" "blue")</span></p></td></tr><tr><td><span class="stt">&gt; </span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">list</span></span></span><span class="hspace">&nbsp;</span><span class="RktVal">1</span><span class="hspace">&nbsp;</span><span class="RktVal">2</span><span class="hspace">&nbsp;</span><span class="RktVal">3</span><span class="hspace">&nbsp;</span><span class="RktVal">4</span><span class="hspace">&nbsp;</span><span class="RktVal">5</span><span class="RktPn">)</span></td></tr><tr><td><p><span class="RktRes">'(1 2 3 4 5)</span></p></td></tr></table></blockquote><blockquote class="refpara"><blockquote class="refcolumn"><blockquote class="refcontent"><p>&#19968;&#20010;&#21015;&#34920;&#36890;&#24120;&#29992;<span class="RktInBG"><span class="hspace"></span><span class="RktIn">'</span><span class="hspace"></span></span>&#25171;&#21360;&#65292;&#20294;&#26159;&#19968;&#20010;&#21015;&#34920;&#30340;&#25171;&#21360;&#24418;&#24335;&#21462;&#20915;&#20110;&#23427;&#30340;&#20869;&#23481;&#12290;&#26356;&#22810;&#20449;&#24687;&#35831;&#30475;&#12298;<a href="pairs.html" data-pltdoc="x">&#28857;&#23545;&#65288;Pair&#65289;&#21644;&#21015;&#34920;&#65288;List&#65289;</a>&#12299;&#12290;</p></blockquote></blockquote></blockquote><p>&#23601;&#22914;&#20320;&#33021;&#22815;&#30475;&#21040;&#30340;&#37027;&#26679;&#65292;&#19968;&#20010;&#21015;&#34920;&#32467;&#26524;&#22312;<a href="intro.html#%28tech._repl%29" class="techoutside" data-pltdoc="x"><span class="techinside">REPL</span></a>&#20013;&#25171;&#21360;&#20026;&#19968;&#20010;&#24341;&#29992;<span class="RktInBG"><span class="hspace"></span><span class="RktIn">'</span><span class="hspace"></span></span>&#65292;&#24182;&#19988;&#37319;&#29992;&#19968;&#23545;&#22278;&#25324;&#21495;&#21253;&#22260;&#36825;&#20010;&#21015;&#34920;&#20803;&#32032;&#30340;&#25171;&#21360;&#34920;&#12290;&#36825;&#37324;&#26377;&#19968;&#20010;&#23481;&#26131;&#28151;&#28102;&#30340;&#22320;&#26041;&#65292;&#22240;&#20026;&#20004;&#20010;&#34920;&#36798;&#24335;&#37117;&#20351;&#29992;&#22278;&#25324;&#21495;&#65292;&#27604;&#22914;<span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">list</span></span></span><span class="stt"> </span><span class="RktVal">"red"</span><span class="stt"> </span><span class="RktVal">"green"</span><span class="stt"> </span><span class="RktVal">"blue"</span><span class="RktPn">)</span>&#65292;&#37027;&#20040;&#25171;&#21360;&#32467;&#26524;&#20026;<span class="RktRes">'("red"<span class="stt"> </span>"green"<span class="stt"> </span>"blue")</span>&#12290;&#38500;&#20102;&#24341;&#29992;&#65292;&#32467;&#26524;&#30340;&#22278;&#25324;&#21495;&#22312;&#25991;&#26723;&#20013;&#21644;&#22312;DrRacket&#20013;&#25171;&#21360;&#20026;&#34013;&#33394;&#65292;&#32780;&#34920;&#36798;&#24335;&#30340;&#22278;&#25324;&#21495;&#26159;&#26837;&#33394;&#30340;&#12290;</p><p>&#22312;&#21015;&#34920;&#26041;&#38754;&#26377;&#35768;&#22810;&#39044;&#23450;&#20041;&#30340;&#20989;&#25968;&#25805;&#20316;&#12290;&#19979;&#38754;&#26159;&#23569;&#35768;&#20363;&#23376;&#65306;</p><blockquote class="SCodeFlow"><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><span class="stt">&gt; </span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">length</span></span></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">list</span></span></span><span class="hspace">&nbsp;</span><span class="RktVal">"hop"</span><span class="hspace">&nbsp;</span><span class="RktVal">"skip"</span><span class="hspace">&nbsp;</span><span class="RktVal">"jump"</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktCmt">;</span><span class="RktCmt">&nbsp;</span><span class="RktCmt">count the elements</span></td></tr><tr><td><p><span class="RktRes">3</span></p></td></tr><tr><td><span class="stt">&gt; </span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">list-ref</span></span></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">list</span></span></span><span class="hspace">&nbsp;</span><span class="RktVal">"hop"</span><span class="hspace">&nbsp;</span><span class="RktVal">"skip"</span><span class="hspace">&nbsp;</span><span class="RktVal">"jump"</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktVal">0</span><span class="RktPn">)</span><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktCmt">;</span><span class="RktCmt">&nbsp;</span><span class="RktCmt">extract by position</span></td></tr><tr><td><p><span class="RktRes">"hop"</span></p></td></tr><tr><td><span class="stt">&gt; </span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">list-ref</span></span></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">list</span></span></span><span class="hspace">&nbsp;</span><span class="RktVal">"hop"</span><span class="hspace">&nbsp;</span><span class="RktVal">"skip"</span><span class="hspace">&nbsp;</span><span class="RktVal">"jump"</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktVal">1</span><span class="RktPn">)</span></td></tr><tr><td><p><span class="RktRes">"skip"</span></p></td></tr><tr><td><span class="stt">&gt; </span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">append</span></span></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">list</span></span></span><span class="hspace">&nbsp;</span><span class="RktVal">"hop"</span><span class="hspace">&nbsp;</span><span class="RktVal">"skip"</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">list</span></span></span><span class="hspace">&nbsp;</span><span class="RktVal">"jump"</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktCmt">;</span><span class="RktCmt">&nbsp;</span><span class="RktCmt">combine lists</span></td></tr><tr><td><p><span class="RktRes">'("hop" "skip" "jump")</span></p></td></tr><tr><td><span class="stt">&gt; </span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">reverse</span></span></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">list</span></span></span><span class="hspace">&nbsp;</span><span class="RktVal">"hop"</span><span class="hspace">&nbsp;</span><span class="RktVal">"skip"</span><span class="hspace">&nbsp;</span><span class="RktVal">"jump"</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktCmt">;</span><span class="RktCmt">&nbsp;</span><span class="RktCmt">reverse order</span></td></tr><tr><td><p><span class="RktRes">'("jump" "skip" "hop")</span></p></td></tr><tr><td><span class="stt">&gt; </span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">member</span></span></span><span class="hspace">&nbsp;</span><span class="RktVal">"fall"</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">list</span></span></span><span class="hspace">&nbsp;</span><span class="RktVal">"hop"</span><span class="hspace">&nbsp;</span><span class="RktVal">"skip"</span><span class="hspace">&nbsp;</span><span class="RktVal">"jump"</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktCmt">;</span><span class="RktCmt">&nbsp;</span><span class="RktCmt">check for an element</span></td></tr><tr><td><p><span class="RktRes">#f</span></p></td></tr></table></blockquote><h5>2.3.1<tt>&nbsp;</tt><a name="(part._.Predefined-.List-.Loops)"></a>&#39044;&#23450;&#20041;&#21015;&#34920;&#24490;&#29615;</h5><p>&#38500;&#20102;&#20687;<span class="RktSym"><span class="badlink"><span class="RktValLink">append</span></span></span>&#36825;&#26679;&#30340;&#31616;&#21333;&#25805;&#20316;&#65292;Racket&#36824;&#21253;&#25324;&#36941;&#21382;&#21015;&#34920;&#20803;&#32032;&#30340;&#20989;&#25968;&#12290;&#36825;&#20123;&#36845;&#20195;&#20989;&#25968;&#25198;&#28436;&#31867;&#20284;&#20110;java&#12289;Racket&#21450;&#20854;&#23427;&#35821;&#35328;&#37324;&#30340;<span class="RktSym"><span class="badlink"><span class="RktValLink">for</span></span></span>&#19968;&#20010;&#35282;&#33394;&#12290;&#19968;&#20010;Racket&#36845;&#20195;&#30340;&#20027;&#20307;&#34987;&#25171;&#21253;&#25104;&#19968;&#20010;&#24212;&#29992;&#20110;&#27599;&#20010;&#20803;&#32032;&#30340;&#20989;&#25968;&#65292;&#25152;&#20197;<span class="RktSym"><span class="badlink"><span class="RktValLink">lambda</span></span></span>&#34920;&#22312;&#19982;&#36845;&#20195;&#20989;&#25968;&#30340;&#32452;&#21512;&#20013;&#21464;&#24471;&#29305;&#21035;&#26041;&#20415;&#12290;</p><p>&#19981;&#21516;&#30340;&#21015;&#34920;&#36845;&#20195;&#20989;&#25968;&#22312;&#19981;&#21516;&#30340;&#26041;&#24335;&#20013;&#32452;&#21512;&#36845;&#20195;&#32467;&#26524;&#12290;<span class="RktSym"><span class="badlink"><span class="RktValLink">map</span></span></span>&#20989;&#25968;&#20351;&#29992;&#27599;&#20010;&#20803;&#32032;&#32467;&#26524;&#21019;&#24314;&#19968;&#20010;&#26032;&#21015;&#34920;&#65306;</p><blockquote class="SCodeFlow"><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><span class="stt">&gt; </span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">map</span></span></span><span class="hspace">&nbsp;</span><span class="RktSym"><span class="badlink"><span class="RktValLink">sqrt</span></span></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">list</span></span></span><span class="hspace">&nbsp;</span><span class="RktVal">1</span><span class="hspace">&nbsp;</span><span class="RktVal">4</span><span class="hspace">&nbsp;</span><span class="RktVal">9</span><span class="hspace">&nbsp;</span><span class="RktVal">16</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><p><span class="RktRes">'(1 2 3 4)</span></p></td></tr><tr><td><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><span class="stt">&gt; </span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">map</span></span></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">lambda</span></span></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">i</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">string-append</span></span></span><span class="hspace">&nbsp;</span><span class="RktSym">i</span><span class="hspace">&nbsp;</span><span class="RktVal">"!"</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">list</span></span></span><span class="hspace">&nbsp;</span><span class="RktVal">"peanuts"</span><span class="hspace">&nbsp;</span><span class="RktVal">"popcorn"</span><span class="hspace">&nbsp;</span><span class="RktVal">"crackerjack"</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr></table></td></tr><tr><td><p><span class="RktRes">'("peanuts!" "popcorn!" "crackerjack!")</span></p></td></tr></table></blockquote><p><span class="RktSym"><span class="badlink"><span class="RktValLink">andmap</span></span></span>&#21644;<span class="RktSym"><span class="badlink"><span class="RktValLink">ormap</span></span></span>&#20989;&#25968;&#36890;&#36807;<span class="RktSym"><span class="badlink"><span class="RktValLink">and</span></span></span>&#25110;<span class="RktSym"><span class="badlink"><span class="RktValLink">or</span></span></span>&#32467;&#21512;&#32467;&#26524;&#65306;</p><blockquote class="SCodeFlow"><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><span class="stt">&gt; </span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">andmap</span></span></span><span class="hspace">&nbsp;</span><span class="RktSym"><span class="badlink"><span class="RktValLink">string?</span></span></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">list</span></span></span><span class="hspace">&nbsp;</span><span class="RktVal">"a"</span><span class="hspace">&nbsp;</span><span class="RktVal">"b"</span><span class="hspace">&nbsp;</span><span class="RktVal">"c"</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><p><span class="RktRes">#t</span></p></td></tr><tr><td><span class="stt">&gt; </span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">andmap</span></span></span><span class="hspace">&nbsp;</span><span class="RktSym"><span class="badlink"><span class="RktValLink">string?</span></span></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">list</span></span></span><span class="hspace">&nbsp;</span><span class="RktVal">"a"</span><span class="hspace">&nbsp;</span><span class="RktVal">"b"</span><span class="hspace">&nbsp;</span><span class="RktVal">6</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><p><span class="RktRes">#f</span></p></td></tr><tr><td><span class="stt">&gt; </span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">ormap</span></span></span><span class="hspace">&nbsp;</span><span class="RktSym"><span class="badlink"><span class="RktValLink">number?</span></span></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">list</span></span></span><span class="hspace">&nbsp;</span><span class="RktVal">"a"</span><span class="hspace">&nbsp;</span><span class="RktVal">"b"</span><span class="hspace">&nbsp;</span><span class="RktVal">6</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><p><span class="RktRes">#t</span></p></td></tr></table></blockquote><p><span class="RktSym"><span class="badlink"><span class="RktValLink">map</span></span></span>&#12289;<span class="RktSym"><span class="badlink"><span class="RktValLink">andmap</span></span></span>&#21644;<span class="RktSym"><span class="badlink"><span class="RktValLink">ormap</span></span></span>&#20989;&#25968;&#37117;&#21487;&#20197;&#22788;&#29702;&#22810;&#20010;&#21015;&#34920;&#65292;&#32780;&#19981;&#21482;&#26159;&#19968;&#20010;&#21333;&#19968;&#30340;&#21015;&#34920;&#12290;&#36825;&#20123;&#21015;&#34920;&#37117;&#24517;&#39035;&#20855;&#26377;&#30456;&#21516;&#30340;&#38271;&#24230;&#65292;&#24182;&#19988;&#32473;&#23450;&#30340;&#20989;&#25968;&#24517;&#39035;&#23545;&#27599;&#20010;&#21015;&#34920;&#25509;&#21463;&#19968;&#20010;&#21442;&#25968;&#65306;</p><blockquote class="SCodeFlow"><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><span class="stt">&gt; </span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">map</span></span></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">lambda</span></span></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">s</span><span class="hspace">&nbsp;</span><span class="RktSym">n</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">substring</span></span></span><span class="hspace">&nbsp;</span><span class="RktSym">s</span><span class="hspace">&nbsp;</span><span class="RktVal">0</span><span class="hspace">&nbsp;</span><span class="RktSym">n</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">list</span></span></span><span class="hspace">&nbsp;</span><span class="RktVal">"peanuts"</span><span class="hspace">&nbsp;</span><span class="RktVal">"popcorn"</span><span class="hspace">&nbsp;</span><span class="RktVal">"crackerjack"</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">list</span></span></span><span class="hspace">&nbsp;</span><span class="RktVal">6</span><span class="hspace">&nbsp;</span><span class="RktVal">3</span><span class="hspace">&nbsp;</span><span class="RktVal">7</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr></table></td></tr><tr><td><p><span class="RktRes">'("peanut" "pop" "cracker")</span></p></td></tr></table></blockquote><p><span class="RktSym"><span class="badlink"><span class="RktValLink">filter</span></span></span>&#20989;&#25968;&#20445;&#25345;&#20854;&#20027;&#20307;&#32467;&#26524;&#26159;&#30495;&#30340;&#20803;&#32032;&#65292;&#24182;&#24573;&#30053;&#20854;&#20027;&#20307;&#32467;&#26524;&#26159;<span class="RktVal">#f</span>&#30340;&#20803;&#32032;&#65306;</p><blockquote class="SCodeFlow"><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><span class="stt">&gt; </span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">filter</span></span></span><span class="hspace">&nbsp;</span><span class="RktSym"><span class="badlink"><span class="RktValLink">string?</span></span></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">list</span></span></span><span class="hspace">&nbsp;</span><span class="RktVal">"a"</span><span class="hspace">&nbsp;</span><span class="RktVal">"b"</span><span class="hspace">&nbsp;</span><span class="RktVal">6</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><p><span class="RktRes">'("a" "b")</span></p></td></tr><tr><td><span class="stt">&gt; </span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">filter</span></span></span><span class="hspace">&nbsp;</span><span class="RktSym"><span class="badlink"><span class="RktValLink">positive?</span></span></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">list</span></span></span><span class="hspace">&nbsp;</span><span class="RktVal">1</span><span class="hspace">&nbsp;</span><span class="RktVal"><span class="nobreak">-2</span></span><span class="hspace">&nbsp;</span><span class="RktVal">6</span><span class="hspace">&nbsp;</span><span class="RktVal">7</span><span class="hspace">&nbsp;</span><span class="RktVal">0</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><p><span class="RktRes">'(1 6 7)</span></p></td></tr></table></blockquote><p><span class="RktSym"><span class="badlink"><span class="RktValLink">foldl</span></span></span>&#20989;&#25968;&#21253;&#21547;&#26576;&#20123;&#36845;&#20195;&#20989;&#25968;&#12290;&#23427;&#20351;&#29992;&#27599;&#20010;&#20803;&#32032;&#20989;&#25968;&#22788;&#29702;&#19968;&#20010;&#20803;&#32032;&#24182;&#23558;&#20854;&#19982;&#8220;&#24403;&#21069;&#8221;&#20540;&#30456;&#32467;&#21512;&#65292;&#22240;&#27492;&#27599;&#20010;&#20803;&#32032;&#20989;&#25968;&#25509;&#21463;&#39069;&#22806;&#30340;&#31532;&#19968;&#20010;&#21442;&#25968;&#12290;&#21478;&#22806;&#65292;&#22312;&#21015;&#34920;&#20043;&#21069;&#24517;&#39035;&#25552;&#20379;&#19968;&#20010;&#24320;&#22987;&#30340;&#8220;&#24403;&#21069;&#8221;&#20540;&#65306;</p><blockquote class="SCodeFlow"><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><span class="stt">&gt; </span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">foldl</span></span></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">lambda</span></span></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">elem</span><span class="hspace">&nbsp;</span><span class="RktSym">v</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">+</span></span></span><span class="hspace">&nbsp;</span><span class="RktSym">v</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">*</span></span></span><span class="hspace">&nbsp;</span><span class="RktSym">elem</span><span class="hspace">&nbsp;</span><span class="RktSym">elem</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktVal">0</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktVal">'</span><span class="RktVal">(</span><span class="RktVal">1</span><span class="hspace">&nbsp;</span><span class="RktVal">2</span><span class="hspace">&nbsp;</span><span class="RktVal">3</span><span class="RktVal">)</span><span class="RktPn">)</span></td></tr></table></td></tr><tr><td><p><span class="RktRes">14</span></p></td></tr></table></blockquote><p>&#23613;&#31649;&#26377;&#20854;&#20849;&#24615;&#65292;<span class="RktSym"><span class="badlink"><span class="RktValLink">foldl</span></span></span>&#19981;&#26159;&#20687;&#20854;&#23427;&#20989;&#25968;&#19968;&#26679;&#21463;&#27426;&#36814;&#12290;&#19968;&#20010;&#21407;&#22240;&#26159;<span class="RktSym"><span class="badlink"><span class="RktValLink">map</span></span></span>&#12289; <span class="RktSym"><span class="badlink"><span class="RktValLink">ormap</span></span></span>&#12289;<span class="RktSym"><span class="badlink"><span class="RktValLink">andmap</span></span></span>&#21644;<span class="RktSym"><span class="badlink"><span class="RktValLink">filter</span></span></span>&#35206;&#30422;&#20102;&#26368;&#24120;&#35265;&#30340;&#21015;&#34920;&#36845;&#20195;&#12290;</p><p>Racket&#25552;&#20379;&#20102;&#19968;&#20010;&#36890;&#29992;&#30340;<span style="font-style: italic">&#21015;&#34920;&#29702;&#35299;</span>&#34920;<span class="RktSym"><span class="badlink"><span class="RktValLink">for/list</span></span></span>&#65292;&#23427;&#29992;&#36845;&#20195;&#36890;&#36807;<span style="font-style: italic">&#24207;&#21015;&#65288;sequences&#65289;</span>&#26469;&#24314;&#31435;&#19968;&#20010;&#21015;&#34920;&#12290;&#21015;&#34920;&#29702;&#35299;&#34920;&#21644;&#30456;&#20851;&#36845;&#20195;&#34920;&#23558;&#22312;&#12298;<a href="for.html" data-pltdoc="x">&#36845;&#20195;&#21644;&#25512;&#23548;</a>&#12299;&#37096;&#20998;&#25551;&#36848;&#12290;</p><h5>2.3.2<tt>&nbsp;</tt><a name="(part._.List-.Iteration-from-.Scratch)"></a>&#20174;&#22836;&#24320;&#22987;&#21015;&#34920;&#36845;&#20195;</h5><p>&#23613;&#31649;<span class="RktSym"><span class="badlink"><span class="RktValLink">map</span></span></span>&#21644;&#20854;&#23427;&#36845;&#20195;&#20989;&#25968;&#26159;&#39044;&#23450;&#20041;&#30340;&#65292;&#20294;&#23427;&#20204;&#22312;&#20219;&#20309;&#20196;&#20154;&#24863;&#20852;&#36259;&#30340;&#24847;&#20041;&#19978;&#37117;&#19981;&#26159;&#21407;&#22987;&#30340;&#12290;&#20351;&#29992;&#23569;&#37327;&#21015;&#34920;&#21407;&#35821;&#21363;&#33021;&#32534;&#20889;&#31561;&#25928;&#36845;&#20195;&#12290;</p><p>&#30001;&#20110;&#19968;&#20010;Racket&#21015;&#34920;&#26159;&#19968;&#20010;&#38142;&#34920;&#65292;&#23545;&#38750;&#31354;&#21015;&#34920;&#30340;&#20004;&#20010;&#26680;&#24515;&#25805;&#20316;&#26159;:</p><ul><li><p><span class="RktSym"><span class="badlink"><span class="RktValLink">first</span></span></span>&#65306;&#21462;&#24471;&#21015;&#34920;&#19978;&#30340;&#31532;&#19968;&#20010;&#20803;&#32032;&#65307;</p></li><li><p><span class="RktSym"><span class="badlink"><span class="RktValLink">rest</span></span></span>&#65306;&#33719;&#21462;&#21015;&#34920;&#30340;&#20854;&#20313;&#37096;&#20998;&#12290;</p></li></ul><p><div class="SIntrapara">Examples:</div><div class="SIntrapara"><blockquote class="SCodeFlow"><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><span class="stt">&gt; </span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">first</span></span></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">list</span></span></span><span class="hspace">&nbsp;</span><span class="RktVal">1</span><span class="hspace">&nbsp;</span><span class="RktVal">2</span><span class="hspace">&nbsp;</span><span class="RktVal">3</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><p><span class="RktRes">1</span></p></td></tr><tr><td><span class="stt">&gt; </span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">rest</span></span></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">list</span></span></span><span class="hspace">&nbsp;</span><span class="RktVal">1</span><span class="hspace">&nbsp;</span><span class="RktVal">2</span><span class="hspace">&nbsp;</span><span class="RktVal">3</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><p><span class="RktRes">'(2 3)</span></p></td></tr></table></blockquote></div></p><p>&#20026;&#19968;&#20010;&#38142;&#34920;&#28155;&#21152;&#19968;&#20010;&#26032;&#30340;&#33410;&#28857;&#8212;&#8212;&#30830;&#20999;&#22320;&#35828;&#65292;&#28155;&#21152;&#21040;&#36825;&#20010;&#21015;&#34920;&#30340;&#21069;&#38754;&#8212;&#8212;&#20351;&#29992;<span class="RktSym"><span class="badlink"><span class="RktValLink">cons</span></span></span>&#20989;&#25968;&#65292;&#23427;&#26159;&#8220;construct&#8221;&#65288;&#26500;&#36896;&#65289;&#30340;&#32553;&#20889;&#12290;&#35201;&#24471;&#21040;&#19968;&#20010;&#31354;&#21015;&#34920;&#29992;&#20110;&#24320;&#22987;&#65292;&#29992;<span class="RktSym"><span class="badlink"><span class="RktValLink">empty</span></span></span>&#26469;&#26500;&#36896;&#65306;</p><blockquote class="SCodeFlow"><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><span class="stt">&gt; </span><span class="RktSym"><span class="badlink"><span class="RktValLink">empty</span></span></span></td></tr><tr><td><p><span class="RktRes">'()</span></p></td></tr><tr><td><span class="stt">&gt; </span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">cons</span></span></span><span class="hspace">&nbsp;</span><span class="RktVal">"head"</span><span class="hspace">&nbsp;</span><span class="RktSym"><span class="badlink"><span class="RktValLink">empty</span></span></span><span class="RktPn">)</span></td></tr><tr><td><p><span class="RktRes">'("head")</span></p></td></tr><tr><td><span class="stt">&gt; </span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">cons</span></span></span><span class="hspace">&nbsp;</span><span class="RktVal">"dead"</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">cons</span></span></span><span class="hspace">&nbsp;</span><span class="RktVal">"head"</span><span class="hspace">&nbsp;</span><span class="RktSym"><span class="badlink"><span class="RktValLink">empty</span></span></span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><p><span class="RktRes">'("dead" "head")</span></p></td></tr></table></blockquote><p>&#35201;&#22788;&#29702;&#19968;&#20010;&#21015;&#34920;&#65292;&#20320;&#38656;&#35201;&#33021;&#22815;&#21306;&#20998;&#31354;&#21015;&#34920;&#21644;&#38750;&#31354;&#21015;&#34920;&#65292;&#22240;&#20026;<span class="RktSym"><span class="badlink"><span class="RktValLink">first</span></span></span>&#21644;<span class="RktSym"><span class="badlink"><span class="RktValLink">rest</span></span></span>&#21482;&#22312;&#38750;&#31354;&#21015;&#34920;&#19978;&#24037;&#20316;&#12290;<span class="RktSym"><span class="badlink"><span class="RktValLink">empty?</span></span></span>&#20989;&#25968;&#26816;&#27979;&#31354;&#21015;&#34920;&#65292;<span class="RktSym"><span class="badlink"><span class="RktValLink">cons?</span></span></span>&#26816;&#27979;&#38750;&#31354;&#21015;&#34920;&#65306;</p><blockquote class="SCodeFlow"><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><span class="stt">&gt; </span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">empty?</span></span></span><span class="hspace">&nbsp;</span><span class="RktSym"><span class="badlink"><span class="RktValLink">empty</span></span></span><span class="RktPn">)</span></td></tr><tr><td><p><span class="RktRes">#t</span></p></td></tr><tr><td><span class="stt">&gt; </span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">empty?</span></span></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">cons</span></span></span><span class="hspace">&nbsp;</span><span class="RktVal">"head"</span><span class="hspace">&nbsp;</span><span class="RktSym"><span class="badlink"><span class="RktValLink">empty</span></span></span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><p><span class="RktRes">#f</span></p></td></tr><tr><td><span class="stt">&gt; </span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">cons?</span></span></span><span class="hspace">&nbsp;</span><span class="RktSym"><span class="badlink"><span class="RktValLink">empty</span></span></span><span class="RktPn">)</span></td></tr><tr><td><p><span class="RktRes">#f</span></p></td></tr><tr><td><span class="stt">&gt; </span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">cons?</span></span></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">cons</span></span></span><span class="hspace">&nbsp;</span><span class="RktVal">"head"</span><span class="hspace">&nbsp;</span><span class="RktSym"><span class="badlink"><span class="RktValLink">empty</span></span></span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><p><span class="RktRes">#t</span></p></td></tr></table></blockquote><p>&#36890;&#36807;&#36825;&#20123;&#29255;&#27573;&#65292;&#20320;&#33021;&#22815;&#32534;&#20889;&#20320;&#33258;&#24049;&#30340;<span class="RktSym"><span class="badlink"><span class="RktValLink">length</span></span></span>&#20989;&#25968;&#12289;<span class="RktSym"><span class="badlink"><span class="RktValLink">map</span></span></span>&#20989;&#25968;&#20197;&#21450;&#26356;&#22810;&#30340;&#20989;&#25968;&#30340;&#29256;&#26412;&#12290;</p><p><div class="SIntrapara"><p><div class="SIntrapara">Examples:</div><div class="SIntrapara"><blockquote class="SCodeFlow"><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">define</span></span></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">my-length</span><span class="hspace">&nbsp;</span><span class="RktSym">lst</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">cond</span></span></span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;</span><span class="RktPn">[</span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">empty?</span></span></span><span class="hspace">&nbsp;</span><span class="RktSym">lst</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktVal">0</span><span class="RktPn">]</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;</span><span class="RktPn">[</span><span class="RktSym"><span class="badlink"><span class="RktValLink">else</span></span></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">+</span></span></span><span class="hspace">&nbsp;</span><span class="RktVal">1</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">my-length</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">rest</span></span></span><span class="hspace">&nbsp;</span><span class="RktSym">lst</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">]</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td> </td></tr></table></td></tr><tr><td><span class="stt">&gt; </span><span class="RktPn">(</span><span class="RktSym">my-length</span><span class="hspace">&nbsp;</span><span class="RktSym"><span class="badlink"><span class="RktValLink">empty</span></span></span><span class="RktPn">)</span></td></tr><tr><td><p><span class="RktRes">0</span></p></td></tr><tr><td><span class="stt">&gt; </span><span class="RktPn">(</span><span class="RktSym">my-length</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">list</span></span></span><span class="hspace">&nbsp;</span><span class="RktVal">"a"</span><span class="hspace">&nbsp;</span><span class="RktVal">"b"</span><span class="hspace">&nbsp;</span><span class="RktVal">"c"</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><p><span class="RktRes">3</span></p></td></tr></table></blockquote></div></p></div><div class="SIntrapara"><blockquote class="SCodeFlow"><table cellspacing="0" cellpadding="0"><tr><td><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">define</span></span></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">my-map</span><span class="hspace">&nbsp;</span><span class="RktSym">f</span><span class="hspace">&nbsp;</span><span class="RktSym">lst</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">cond</span></span></span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;</span><span class="RktPn">[</span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">empty?</span></span></span><span class="hspace">&nbsp;</span><span class="RktSym">lst</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym"><span class="badlink"><span class="RktValLink">empty</span></span></span><span class="RktPn">]</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;</span><span class="RktPn">[</span><span class="RktSym"><span class="badlink"><span class="RktValLink">else</span></span></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">cons</span></span></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">f</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">first</span></span></span><span class="hspace">&nbsp;</span><span class="RktSym">lst</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">my-map</span><span class="hspace">&nbsp;</span><span class="RktSym">f</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">rest</span></span></span><span class="hspace">&nbsp;</span><span class="RktSym">lst</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">]</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr></table></td></tr><tr><td><p>&nbsp;</p></td></tr><tr><td><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><span class="stt">&gt; </span><span class="RktPn">(</span><span class="RktSym">my-map</span><span class="hspace">&nbsp;</span><span class="RktSym"><span class="badlink"><span class="RktValLink">string-upcase</span></span></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">list</span></span></span><span class="hspace">&nbsp;</span><span class="RktVal">"ready"</span><span class="hspace">&nbsp;</span><span class="RktVal">"set"</span><span class="hspace">&nbsp;</span><span class="RktVal">"go"</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><p><span class="RktRes">'("READY" "SET" "GO")</span></p></td></tr></table></td></tr></table></blockquote></div></p><p>&#22914;&#26524;&#19978;&#36848;&#23450;&#20041;&#30340;&#27966;&#29983;&#23545;&#20320;&#26469;&#35828;&#38590;&#20197;&#29702;&#35299;&#65292;&#24314;&#35758;&#21435;&#35835;&#12298;<span style="font-style: italic"><a href="http://www.htdp.org">How to Design Programs</a></span>&#65288;&#22914;&#20309;&#35774;&#35745;&#31243;&#24207;&#65289;&#12299;&#12290;&#22914;&#26524;&#20320;&#21482;&#23545;&#20351;&#29992;&#36882;&#24402;&#35843;&#29992;&#34920;&#31034;&#19981;&#20449;&#20219;&#65292;&#32780;&#19981;&#26159;&#24490;&#29615;&#32467;&#26500;&#65292;&#37027;&#23601;&#32487;&#32493;&#24448;&#21518;&#35835;&#12290;</p><h5>2.3.3<tt>&nbsp;</tt><a name="(part._tail-recursion)"></a>&#23614;&#36882;&#24402;</h5><p><span class="RktSym">my-length</span>&#20989;&#25968;&#21644;<span class="RktSym">my-map</span>&#20989;&#25968;&#37117;&#20026;&#19968;&#20010; <span style="font-style: italic">n</span>&#38271;&#24230;&#30340;&#21015;&#34920;&#22312;<span style="font-style: italic">O</span>(<span style="font-style: italic">n</span>)<span style="font-style: italic"></span>&#31354;&#38388;&#20869;&#36816;&#34892;&#12290;&#36890;&#36807;&#24819;&#35937;&#23601;&#24456;&#23481;&#26131;&#26126;&#30333;&#24517;&#39035;&#24590;&#26679;<span class="RktPn">(</span><span class="RktSym">my-length</span><span class="stt"> </span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">list</span></span></span><span class="stt"> </span><span class="RktVal">"a"</span><span class="stt"> </span><span class="RktVal">"b"</span><span class="stt"> </span><span class="RktVal">"c"</span><span class="RktPn">)</span><span class="RktPn">)</span>&#27714;&#20540;&#65306;</p><blockquote class="SCodeFlow"><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><span class="RktPn">(</span><span class="RktSym">my-length</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">list</span></span></span><span class="hspace">&nbsp;</span><span class="RktVal">"a"</span><span class="hspace">&nbsp;</span><span class="RktVal">"b"</span><span class="hspace">&nbsp;</span><span class="RktVal">"c"</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td>=<span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">+</span></span></span><span class="hspace">&nbsp;</span><span class="RktVal">1</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">my-length</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">list</span></span></span><span class="hspace">&nbsp;</span><span class="RktVal">"b"</span><span class="hspace">&nbsp;</span><span class="RktVal">"c"</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td>=<span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">+</span></span></span><span class="hspace">&nbsp;</span><span class="RktVal">1</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">+</span></span></span><span class="hspace">&nbsp;</span><span class="RktVal">1</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">my-length</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">list</span></span></span><span class="hspace">&nbsp;</span><span class="RktVal">"c"</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td>=<span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">+</span></span></span><span class="hspace">&nbsp;</span><span class="RktVal">1</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">+</span></span></span><span class="hspace">&nbsp;</span><span class="RktVal">1</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">+</span></span></span><span class="hspace">&nbsp;</span><span class="RktVal">1</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">my-length</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">list</span></span></span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td>=<span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">+</span></span></span><span class="hspace">&nbsp;</span><span class="RktVal">1</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">+</span></span></span><span class="hspace">&nbsp;</span><span class="RktVal">1</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">+</span></span></span><span class="hspace">&nbsp;</span><span class="RktVal">1</span><span class="hspace">&nbsp;</span><span class="RktVal">0</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td>=<span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">+</span></span></span><span class="hspace">&nbsp;</span><span class="RktVal">1</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">+</span></span></span><span class="hspace">&nbsp;</span><span class="RktVal">1</span><span class="hspace">&nbsp;</span><span class="RktVal">1</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td>=<span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">+</span></span></span><span class="hspace">&nbsp;</span><span class="RktVal">1</span><span class="hspace">&nbsp;</span><span class="RktVal">2</span><span class="RktPn">)</span></td></tr><tr><td>=<span class="hspace">&nbsp;</span><span class="RktVal">3</span></td></tr></table></blockquote><p>&#23545;&#20110;&#19968;&#20010;&#24102;&#26377;<span style="font-style: italic">n</span>&#20010;&#20803;&#32032;&#30340;&#21015;&#34920;&#65292;&#27714;&#20540;&#23558;&#22534;&#26632;&#21472;&#21152;<span style="font-style: italic">n</span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">+</span></span></span><span class="stt"> </span><span class="RktVal">1</span><span class="stt"> </span><span class="RktSym"><span class="badlink"><span class="RktValLink">...</span></span></span><span class="RktPn">)</span>&#65292;&#24182;&#19988;&#30452;&#21040;&#21015;&#34920;&#29992;&#23436;&#26102;&#26368;&#21518;&#25165;&#25226;&#23427;&#20204;&#21152;&#36215;&#26469;&#12290;</p><p>&#20320;&#21487;&#20197;&#36890;&#36807;&#19968;&#36335;&#27714;&#21644;&#36991;&#20813;&#22534;&#31215;&#28155;&#21152;&#12290;&#35201;&#20197;&#36825;&#31181;&#26041;&#24335;&#32047;&#31215;&#19968;&#20010;&#38271;&#24230;&#65292;&#25105;&#20204;&#38656;&#35201;&#19968;&#20010;&#26082;&#21487;&#20197;&#25805;&#20316;&#21015;&#34920;&#20063;&#21487;&#20197;&#25805;&#20316;&#24403;&#21069;&#21015;&#34920;&#38271;&#24230;&#30340;&#20989;&#25968;&#65307;&#19979;&#38754;&#30340;&#20195;&#30721;&#20351;&#29992;&#19968;&#20010;&#23616;&#37096;&#20989;&#25968;<span class="RktSym">iter</span>&#65292;&#23427;&#22312;&#19968;&#20010;&#21442;&#25968;<span class="RktSym">len</span>&#20013;&#32047;&#31215;&#38271;&#24230;&#65306;</p><blockquote class="SCodeFlow"><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">define</span></span></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">my-length</span><span class="hspace">&nbsp;</span><span class="RktSym">lst</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktCmt">;</span><span class="RktCmt">&nbsp;</span><span class="RktCmt">&#23616;&#37096;&#20989;&#25968;</span><span class="RktSym">iter</span><span class="RktCmt">:</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">define</span></span></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">iter</span><span class="hspace">&nbsp;</span><span class="RktSym">lst</span><span class="hspace">&nbsp;</span><span class="RktSym">len</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">cond</span></span></span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">[</span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">empty?</span></span></span><span class="hspace">&nbsp;</span><span class="RktSym">lst</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">len</span><span class="RktPn">]</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">[</span><span class="RktSym"><span class="badlink"><span class="RktValLink">else</span></span></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">iter</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">rest</span></span></span><span class="hspace">&nbsp;</span><span class="RktSym">lst</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">+</span></span></span><span class="hspace">&nbsp;</span><span class="RktSym">len</span><span class="hspace">&nbsp;</span><span class="RktVal">1</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">]</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktCmt">;</span><span class="RktCmt">&nbsp;</span><span class="RktSym">my-length</span><span class="RktCmt">&#30340;&#20027;&#20307;&#35843;&#29992;</span><span class="RktSym">iter</span><span class="RktCmt">:</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">iter</span><span class="hspace">&nbsp;</span><span class="RktSym">lst</span><span class="hspace">&nbsp;</span><span class="RktVal">0</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr></table></blockquote><p>&#29616;&#22312;&#27714;&#20540;&#36807;&#31243;&#30475;&#36215;&#26469;&#20687;&#36825;&#26679;&#65306;</p><blockquote class="SCodeFlow"><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><span class="RktPn">(</span><span class="RktSym">my-length</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">list</span></span></span><span class="hspace">&nbsp;</span><span class="RktVal">"a"</span><span class="hspace">&nbsp;</span><span class="RktVal">"b"</span><span class="hspace">&nbsp;</span><span class="RktVal">"c"</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td>=<span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">iter</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">list</span></span></span><span class="hspace">&nbsp;</span><span class="RktVal">"a"</span><span class="hspace">&nbsp;</span><span class="RktVal">"b"</span><span class="hspace">&nbsp;</span><span class="RktVal">"c"</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktVal">0</span><span class="RktPn">)</span></td></tr><tr><td>=<span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">iter</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">list</span></span></span><span class="hspace">&nbsp;</span><span class="RktVal">"b"</span><span class="hspace">&nbsp;</span><span class="RktVal">"c"</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktVal">1</span><span class="RktPn">)</span></td></tr><tr><td>=<span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">iter</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">list</span></span></span><span class="hspace">&nbsp;</span><span class="RktVal">"c"</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktVal">2</span><span class="RktPn">)</span></td></tr><tr><td>=<span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">iter</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">list</span></span></span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktVal">3</span><span class="RktPn">)</span></td></tr><tr><td><span class="RktVal">3</span></td></tr></table></blockquote><p>&#20462;&#27491;&#21518;&#30340;<span class="RktSym">my-length</span>&#22312;&#24658;&#23450;&#30340;&#31354;&#38388;&#20013;&#36816;&#34892;&#65292;&#27491;&#22914;&#19978;&#38754;&#25152;&#24314;&#35758;&#30340;&#27714;&#20540;&#27493;&#39588;&#37027;&#26679;&#12290;&#20063;&#23601;&#26159;&#35828;&#65292;&#24403;&#19968;&#20010;&#20989;&#25968;&#35843;&#29992;&#30340;&#32467;&#26524;&#65292;&#20687;<span class="RktPn">(</span><span class="RktSym">iter</span><span class="stt"> </span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">list</span></span></span><span class="stt"> </span><span class="RktVal">"b"</span><span class="stt"> </span><span class="RktVal">"c"</span><span class="RktPn">)</span><span class="stt"> </span><span class="RktVal">1</span><span class="RktPn">)</span>&#65292;&#24688;&#24688;&#26159;&#20854;&#23427;&#20989;&#25968;&#35843;&#29992;&#30340;&#32467;&#26524;&#65292;&#20687;<span class="RktPn">(</span><span class="RktSym">iter</span><span class="stt"> </span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">list</span></span></span><span class="stt"> </span><span class="RktVal">"c"</span><span class="RktPn">)</span><span class="RktPn">)</span>&#65292;&#37027;&#20040;&#31532;&#19968;&#20010;&#20989;&#25968;&#19981;&#38656;&#35201;&#31561;&#24453;&#31532;&#20108;&#20010;&#20989;&#25968;&#22238;&#32469;&#65292;&#22240;&#20026;&#37027;&#26679;&#20250;&#20026;&#20102;&#19981;&#24688;&#24403;&#30340;&#21407;&#22240;&#21344;&#29992;&#31354;&#38388;&#12290;</p><p>&#36825;&#31181;&#27714;&#20540;&#34892;&#20026;&#26377;&#26102;&#31216;&#20026;<span style="font-style: italic">&#8221;&#23614;&#37096;&#35843;&#29992;&#20248;&#21270;(tail-call
optimization)&#8220;</span>&#65292;&#20294;&#23427;&#22312;Racket&#37324;&#19981;&#20165;&#20165;&#26159;&#19968;&#31181;&#8220;&#20248;&#21270;&#8221;&#65292;&#23427;&#26159;&#19968;&#31181;&#20195;&#30721;&#23558;&#35201;&#36816;&#34892;&#30340;&#26041;&#24335;&#30340;&#20445;&#35777;&#12290;&#26356;&#30830;&#20999;&#22320;&#35828;&#65292;&#30456;&#23545;&#20110;&#21478;&#19968;&#34920;&#36798;&#24335;&#30340;&#19968;&#20010;<a name="(tech._~e5~b0~be~e9~83~a8(tail._position))"></a><span style="font-style: italic">&#23614;&#37096;(tail position)</span>&#20301;&#32622;&#30340;&#34920;&#36798;&#24335;&#22312;&#21478;&#19968;&#34920;&#36798;&#24335;&#19978;&#19981;&#21344;&#29992;&#39069;&#22806;&#30340;&#35745;&#31639;&#31354;&#38388;&#12290;</p><p>&#22312;<span class="RktSym">my-map</span>&#20363;&#23376;&#20013;&#65292;<span style="font-style: italic">O</span>(<span style="font-style: italic">n</span>)<span style="font-style: italic"></span>&#31354;&#38388;&#22797;&#26434;&#24230;&#26159;&#21512;&#29702;&#30340;&#65292;&#22240;&#20026;&#23427;&#24517;&#39035;&#29983;&#25104;&#19968;&#20010;<span style="font-style: italic">O</span>(<span style="font-style: italic">n</span>)<span style="font-style: italic"></span>&#22823;&#23567;&#30340;&#32467;&#26524;&#12290;&#19981;&#36807;&#65292;&#20320;&#21487;&#20197;&#36890;&#36807;&#32047;&#31215;&#32467;&#26524;&#21015;&#34920;&#26469;&#20943;&#23569;&#24120;&#37327;&#22240;&#23376;&#12290;&#21807;&#19968;&#30340;&#38382;&#39064;&#26159;&#32047;&#31215;&#30340;&#21015;&#34920;&#23558;&#26159;&#21521;&#21518;&#30340;&#65292;&#25152;&#20197;&#20320;&#23558;&#19981;&#24471;&#19981;&#22312;&#27599;&#20010;&#32467;&#23614;&#22788;&#21453;&#36716;&#23427;&#65306;</p><blockquote class="refpara"><blockquote class="refcolumn"><blockquote class="refcontent"><p>&#22914;&#19979;&#38754;&#25152;&#36848;&#65292;&#35797;&#22270;&#20943;&#23569;&#20687;&#36825;&#26679;&#30340;&#19968;&#20010;&#24120;&#37327;&#22240;&#23376;&#36890;&#24120;&#26159;&#19981;&#20540;&#24471;&#30340;&#12290;</p></blockquote></blockquote></blockquote><blockquote class="SCodeFlow"><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">define</span></span></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">my-map</span><span class="hspace">&nbsp;</span><span class="RktSym">f</span><span class="hspace">&nbsp;</span><span class="RktSym">lst</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">define</span></span></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">iter</span><span class="hspace">&nbsp;</span><span class="RktSym">lst</span><span class="hspace">&nbsp;</span><span class="RktSym">backward-result</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">cond</span></span></span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">[</span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">empty?</span></span></span><span class="hspace">&nbsp;</span><span class="RktSym">lst</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">reverse</span></span></span><span class="hspace">&nbsp;</span><span class="RktSym">backward-result</span><span class="RktPn">)</span><span class="RktPn">]</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">[</span><span class="RktSym"><span class="badlink"><span class="RktValLink">else</span></span></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">iter</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">rest</span></span></span><span class="hspace">&nbsp;</span><span class="RktSym">lst</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">cons</span></span></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">f</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">first</span></span></span><span class="hspace">&nbsp;</span><span class="RktSym">lst</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktSym">backward-result</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">]</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">iter</span><span class="hspace">&nbsp;</span><span class="RktSym">lst</span><span class="hspace">&nbsp;</span><span class="RktSym"><span class="badlink"><span class="RktValLink">empty</span></span></span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr></table></blockquote><p>&#20107;&#23454;&#35777;&#26126;&#65292;&#22914;&#26524;&#20320;&#36825;&#26679;&#20889;&#65306;</p><blockquote class="SCodeFlow"><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">define</span></span></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">my-map</span><span class="hspace">&nbsp;</span><span class="RktSym">f</span><span class="hspace">&nbsp;</span><span class="RktSym">lst</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">for/list</span></span></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">[</span><span class="RktSym">i</span><span class="hspace">&nbsp;</span><span class="RktSym">lst</span><span class="RktPn">]</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">f</span><span class="hspace">&nbsp;</span><span class="RktSym">i</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr></table></blockquote><p>&#37027;&#20040;&#20989;&#25968;&#20013;&#30340;<span class="RktSym"><span class="badlink"><span class="RktValLink">for/list</span></span></span>&#34920;&#25193;&#23637;&#21040;&#21644;<span class="RktSym">iter</span>&#20989;&#25968;&#23616;&#37096;&#23450;&#20041;&#21644;&#20351;&#29992;&#22312;&#26412;&#36136;&#19978;&#30456;&#21516;&#30340;&#20195;&#30721;&#12290;&#21306;&#21035;&#20165;&#20165;&#26159;&#21477;&#27861;&#19978;&#30340;&#20415;&#21033;&#12290;</p><h5>2.3.4<tt>&nbsp;</tt><a name="(part._.Recursion-versus-.Iteration)"></a>&#36882;&#24402;&#21644;&#36845;&#20195;</h5><p><span class="RktSym">my-length</span>&#21644;<span class="RktSym">my-map</span>&#31034;&#20363;&#34920;&#26126;&#36845;&#20195;&#21482;&#26159;&#36882;&#24402;&#30340;&#19968;&#20010;&#29305;&#20363;&#12290;&#22312;&#35768;&#22810;&#35821;&#35328;&#20013;&#65292;&#23613;&#21487;&#33021;&#22320;&#23558;&#23613;&#21487;&#33021;&#22810;&#30340;&#35745;&#31639;&#21512;&#24182;&#25104;&#36845;&#20195;&#24418;&#24335;&#26159;&#24456;&#37325;&#35201;&#30340;&#12290;&#21542;&#21017;&#65292;&#24615;&#33021;&#20250;&#21464;&#24046;&#65292;&#19981;&#22826;&#22823;&#30340;&#36755;&#20837;&#37117;&#20250;&#23548;&#33268;&#22534;&#26632;&#28322;&#20986;&#12290;&#31867;&#20284;&#22320;&#65292;&#22312;Racket&#20013;&#65292;&#26377;&#26102;&#24456;&#37325;&#35201;&#30340;&#19968;&#28857;&#26159;&#35201;&#30830;&#20445;&#22312;&#26131;&#20110;&#35745;&#31639;&#30340;&#24120;&#25968;&#31354;&#38388;&#20013;&#20351;&#29992;&#23614;&#36882;&#24402;&#36991;&#20813;<span style="font-style: italic">O</span>(<span style="font-style: italic">n</span>)<span style="font-style: italic"></span>&#31354;&#38388;&#28040;&#32791;&#12290;</p><p>&#28982;&#32780;&#65292;&#22312;Racket&#37324;&#36882;&#24402;&#19981;&#20250;&#23548;&#33268;&#29305;&#21035;&#24046;&#30340;&#24615;&#33021;&#65292;&#32780;&#19988;&#27809;&#26377;&#22534;&#26632;&#28322;&#20986;&#37027;&#26679;&#30340;&#20107;&#24773;&#65307;&#22914;&#26524;&#19968;&#20010;&#35745;&#31639;&#28041;&#21450;&#21040;&#22826;&#22810;&#30340;&#19978;&#19979;&#25991;&#65292;&#20320;&#21487;&#33021;&#32791;&#23613;&#20869;&#23384;&#65292;&#20294;&#32791;&#23613;&#20869;&#23384;&#36890;&#24120;&#38656;&#35201;&#27604;&#21487;&#33021;&#35302;&#21457;&#20854;&#23427;&#35821;&#35328;&#20013;&#30340;&#22534;&#26632;&#28322;&#20986;&#26356;&#22810;&#25968;&#37327;&#32423;&#20197;&#19978;&#30340;&#26356;&#28145;&#23618;&#27425;&#30340;&#36882;&#24402;&#12290;&#22522;&#20110;&#36825;&#20123;&#32771;&#34385;&#22240;&#32032;&#65292;&#21152;&#19978;&#23614;&#36882;&#24402;&#31243;&#24207;&#20250;&#33258;&#21160;&#21644;&#19968;&#20010;&#24490;&#29615;&#19968;&#26679;&#36816;&#34892;&#30340;&#20107;&#23454;&#30456;&#32467;&#21512;&#65292;&#24341;&#23548;Racket&#31243;&#24207;&#21592;&#25509;&#21463;&#36882;&#24402;&#24418;&#24335;&#32780;&#19981;&#26159;&#36991;&#20813;&#23427;&#20204;&#12290;</p><p>&#20363;&#22914;&#65292;&#20551;&#35774;&#20320;&#24819;&#20174;&#19968;&#20010;&#21015;&#34920;&#20013;&#21435;&#38500;&#36830;&#32493;&#30340;&#37325;&#22797;&#39033;&#12290;&#34429;&#28982;&#36825;&#26679;&#30340;&#19968;&#20010;&#20989;&#25968;&#21487;&#20197;&#20889;&#25104;&#19968;&#20010;&#24490;&#29615;&#65292;&#20026;&#27599;&#27425;&#36845;&#20195;&#35760;&#20303;&#21069;&#38754;&#30340;&#20803;&#32032;&#65292;&#20294;&#19968;&#20010;Racket&#31243;&#24207;&#21592;&#26356;&#21487;&#33021;&#21482;&#20889;&#20197;&#19979;&#20869;&#23481;&#65306;</p><blockquote class="SCodeFlow"><table cellspacing="0" cellpadding="0"><tr><td><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">define</span></span></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">remove-dups</span><span class="hspace">&nbsp;</span><span class="RktSym">l</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">cond</span></span></span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;</span><span class="RktPn">[</span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">empty?</span></span></span><span class="hspace">&nbsp;</span><span class="RktSym">l</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym"><span class="badlink"><span class="RktValLink">empty</span></span></span><span class="RktPn">]</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;</span><span class="RktPn">[</span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">empty?</span></span></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">rest</span></span></span><span class="hspace">&nbsp;</span><span class="RktSym">l</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">l</span><span class="RktPn">]</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;</span><span class="RktPn">[</span><span class="RktSym"><span class="badlink"><span class="RktValLink">else</span></span></span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">let</span></span></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">[</span><span class="RktSym">i</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">first</span></span></span><span class="hspace">&nbsp;</span><span class="RktSym">l</span><span class="RktPn">)</span><span class="RktPn">]</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">if</span></span></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">equal?</span></span></span><span class="hspace">&nbsp;</span><span class="RktSym">i</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">first</span></span></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">rest</span></span></span><span class="hspace">&nbsp;</span><span class="RktSym">l</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">remove-dups</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">rest</span></span></span><span class="hspace">&nbsp;</span><span class="RktSym">l</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">cons</span></span></span><span class="hspace">&nbsp;</span><span class="RktSym">i</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">remove-dups</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">rest</span></span></span><span class="hspace">&nbsp;</span><span class="RktSym">l</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">]</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr></table></td></tr><tr><td><p>&nbsp;</p></td></tr><tr><td><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><span class="stt">&gt; </span><span class="RktPn">(</span><span class="RktSym">remove-dups</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">list</span></span></span><span class="hspace">&nbsp;</span><span class="RktVal">"a"</span><span class="hspace">&nbsp;</span><span class="RktVal">"b"</span><span class="hspace">&nbsp;</span><span class="RktVal">"b"</span><span class="hspace">&nbsp;</span><span class="RktVal">"b"</span><span class="hspace">&nbsp;</span><span class="RktVal">"c"</span><span class="hspace">&nbsp;</span><span class="RktVal">"c"</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><p><span class="RktRes">'("a" "b" "c")</span></p></td></tr></table></td></tr></table></blockquote><p>&#19968;&#33324;&#26469;&#35828;&#65292;&#36825;&#20010;&#20989;&#25968;&#20026;&#19968;&#20010;&#38271;&#24230;&#20026;<span style="font-style: italic">n</span>&#30340;&#36755;&#20837;&#21015;&#34920;&#28040;&#32791;<span style="font-style: italic">O</span>(<span style="font-style: italic">n</span>)<span style="font-style: italic"></span>&#30340;&#31354;&#38388;&#65292;&#20294;&#36825;&#24456;&#22909;&#65292;&#22240;&#20026;&#23427;&#20135;&#29983;&#19968;&#20010;<span style="font-style: italic">O</span>(<span style="font-style: italic">n</span>)<span style="font-style: italic"></span>&#32467;&#26524;&#12290;&#22914;&#26524;&#36755;&#20837;&#21015;&#34920;&#24688;&#24039;&#26159;&#36830;&#32493;&#37325;&#22797;&#30340;&#65292;&#37027;&#20040;&#24471;&#21040;&#30340;&#21015;&#34920;&#21487;&#20197;&#27604;<span style="font-style: italic">O</span>(<span style="font-style: italic">n</span>)<span style="font-style: italic"></span>&#23567;&#24471;&#22810;&#8212;&#8212;&#32780;&#19988;<span class="RktSym">remove-dups</span>&#20063;&#23558;&#20351;&#29992;&#27604;<span style="font-style: italic">O</span>(<span style="font-style: italic">n</span>)<span style="font-style: italic"></span>&#26356;&#23569;&#30340;&#31354;&#38388;&#65281;&#21407;&#22240;&#26159;&#24403;&#20989;&#25968;&#25918;&#24323;&#37325;&#22797;&#65292;&#23427;&#36820;&#22238;&#19968;&#20010;<span class="RktSym">remove-dups</span>&#30340;&#30452;&#25509;&#35843;&#29992;&#32467;&#26524;&#65292;&#25152;&#20197;&#23614;&#37096;&#35843;&#29992;&#8220;&#20248;&#21270;&#8221;&#21152;&#20837;&#65306;</p><blockquote class="SCodeFlow"><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><span class="RktPn">(</span><span class="RktSym">remove-dups</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">list</span></span></span><span class="hspace">&nbsp;</span><span class="RktVal">"a"</span><span class="hspace">&nbsp;</span><span class="RktVal">"b"</span><span class="hspace">&nbsp;</span><span class="RktVal">"b"</span><span class="hspace">&nbsp;</span><span class="RktVal">"b"</span><span class="hspace">&nbsp;</span><span class="RktVal">"b"</span><span class="hspace">&nbsp;</span><span class="RktVal">"b"</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td>=<span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">cons</span></span></span><span class="hspace">&nbsp;</span><span class="RktVal">"a"</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">remove-dups</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">list</span></span></span><span class="hspace">&nbsp;</span><span class="RktVal">"b"</span><span class="hspace">&nbsp;</span><span class="RktVal">"b"</span><span class="hspace">&nbsp;</span><span class="RktVal">"b"</span><span class="hspace">&nbsp;</span><span class="RktVal">"b"</span><span class="hspace">&nbsp;</span><span class="RktVal">"b"</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td>=<span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">cons</span></span></span><span class="hspace">&nbsp;</span><span class="RktVal">"a"</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">remove-dups</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">list</span></span></span><span class="hspace">&nbsp;</span><span class="RktVal">"b"</span><span class="hspace">&nbsp;</span><span class="RktVal">"b"</span><span class="hspace">&nbsp;</span><span class="RktVal">"b"</span><span class="hspace">&nbsp;</span><span class="RktVal">"b"</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td>=<span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">cons</span></span></span><span class="hspace">&nbsp;</span><span class="RktVal">"a"</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">remove-dups</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">list</span></span></span><span class="hspace">&nbsp;</span><span class="RktVal">"b"</span><span class="hspace">&nbsp;</span><span class="RktVal">"b"</span><span class="hspace">&nbsp;</span><span class="RktVal">"b"</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td>=<span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">cons</span></span></span><span class="hspace">&nbsp;</span><span class="RktVal">"a"</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">remove-dups</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">list</span></span></span><span class="hspace">&nbsp;</span><span class="RktVal">"b"</span><span class="hspace">&nbsp;</span><span class="RktVal">"b"</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td>=<span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">cons</span></span></span><span class="hspace">&nbsp;</span><span class="RktVal">"a"</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">remove-dups</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">list</span></span></span><span class="hspace">&nbsp;</span><span class="RktVal">"b"</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td>=<span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">cons</span></span></span><span class="hspace">&nbsp;</span><span class="RktVal">"a"</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">list</span></span></span><span class="hspace">&nbsp;</span><span class="RktVal">"b"</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td>=<span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><span class="badlink"><span class="RktValLink">list</span></span></span><span class="hspace">&nbsp;</span><span class="RktVal">"a"</span><span class="hspace">&nbsp;</span><span class="RktVal">"b"</span><span class="RktPn">)</span></td></tr></table></blockquote><div class="navsetbottom"><span class="navleft"><div class="nosearchform"></div>&nbsp;&nbsp;</span><span class="navright">&nbsp;&nbsp;<a href="syntax-overview.html" title="backward to &quot;2.2 简单的定义和表达式&quot;" data-pltdoc="x">&larr; prev</a>&nbsp;&nbsp;<a href="to-scheme.html" title="up to &quot;2 Racket概要&quot;" data-pltdoc="x">up</a>&nbsp;&nbsp;<a href="Pairs-Lists-and-Racket-Syntax.html" title="forward to &quot;2.4 pair、list和Racket的语法&quot;" data-pltdoc="x">next &rarr;</a></span>&nbsp;</div></div></div><div id="contextindicator">&nbsp;</div></body></html>